package com.bean;


public class Record {
    public Record() {
        super();
    }

    private int currentPage = 1; //Trang hien tai se hien thi thong tin user
    private int firstRec = 1; // Ban ghi dau tien trong 1 trang
    private int lastRec; // Ban ghi cuoi cung trong 1 trang
    private int recordOnPage = 5;
    private int totalRec; //Tong so ban ghi cua du lieu
    private int checkNextButton; //Bien kiem tra nut Next
    private int checkPreButton; //Bien kiem tra nut Previous


    public void checkTotalRec() {
        if (totalRec != 0) {
            currentPage = 1;
        }
    }


    public boolean checkCurrentPage() {
        return currentPage == 0 ? false : true;
    }

    public void checkNextButton() {
        int allPage;
        if (totalRec % recordOnPage == 0) {
            allPage = totalRec / recordOnPage;
        } else {
            allPage = totalRec / recordOnPage + 1;
        }
        if ((allPage == 1) || (currentPage == allPage)) {
            checkNextButton = 0;
            return;
        }
        if (currentPage < allPage) {
            checkNextButton = 1;
        }
    }

    public void decreaseTotalRec() {
        totalRec--;
    }

    public void increaseTotalRec() {
        totalRec++;
    }

    public void checkPrevousButton() {
        if(currentPage == 1) {
            checkPreButton = 0;
            return;
        }
        if(currentPage > 1) {
            checkPreButton = 1;
            return;
        }
    }

    public void previousCurrentPage() {
        currentPage--;
    }

    public void nextCurrentPage() {
        currentPage++;
    }

    //    public void compareRealRecWithTotalRec() {
    //        if (totalRec <= lastRec) {
    //            lastRec = totalRec;
    //            checkNext = 0;
    //            checkPrevious = 0;
    //        } else {
    //            checkNext = 1;
    //            checkPrevious = 0;
    //        }
    //    }


    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setFirstRec(int firstRec) {
        this.firstRec = firstRec;
    }

    public int getFirstRec() {
        firstRec = (currentPage - 1) * 5 + 1;
        return firstRec;
    }

    public void setLastRec(int lastRec) {
        this.lastRec = lastRec;
    }

    public int getLastRec() {
        lastRec = firstRec + recordOnPage - 1;
        if (lastRec >= totalRec)
            lastRec = totalRec;
        return lastRec;
    }

    public void setRecordOnPage(int recordOnPage) {
        this.recordOnPage = recordOnPage;
    }

    public int getRecordOnPage() {
        return recordOnPage;
    }

    public void setTotalRec(int totalRec) {
        this.totalRec = totalRec;
    }

    public int getTotalRec() {
        return totalRec;
    }

    public void setCheckNextButton(int checkNextButton) {
        this.checkNextButton = checkNextButton;
    }

    public int getCheckNextButton() {
        return checkNextButton;
    }

    public void setCheckPreButton(int checkPreButton) {
        this.checkPreButton = checkPreButton;
    }

    public int getCheckPreButton() {
        return checkPreButton;
    }
}
